package com.qf.cx.simplenms.webservice.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.qf.cx.simplenms.persist.entity.SubscriberEntity;
import com.qf.cx.simplenms.persist.entity.TopicEntity;

public class Subscriber {
	private long id;
	private String url;
	private String statusUrl;
	private List<String> topicNames = Collections.emptyList();

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getStatusUrl() {
		return statusUrl;
	}

	public void setStatusUrl(String statusUrl) {
		this.statusUrl = statusUrl;
	}

	public List<String> getTopicNames() {
		return topicNames;
	}

	public void setTopicNames(List<String> topicNames) {
		this.topicNames = topicNames;
	}

	public static Subscriber from(SubscriberEntity t) {
		Subscriber o = new Subscriber();
		o.id = t.getId();
		o.url = t.getUrl();
		o.statusUrl = t.getStatusUrl();
		List<String> topicNames = new ArrayList<>();
		for (TopicEntity topicEntity : t.getTopicEntities()) {
			topicNames.add(topicEntity.getName());
		}
		o.setTopicNames(topicNames);
		return o;
	}

	public SubscriberEntity toSubscriberEntity() {
		SubscriberEntity o = new SubscriberEntity();
		o.setId(id);
		o.setUrl(url);
		o.setStatusUrl(statusUrl);
		List<TopicEntity> topicEntities = new ArrayList<>();
		for (String topicName : topicNames) {
			TopicEntity e = new TopicEntity();
			e.setName(topicName);
			topicEntities.add(e);
		}
		o.setTopicEntities(topicEntities);
		return o;
	}

	@Override
	public String toString() {
		return "Subscriber [id=" + id + ", url=" + url + ", statusUrl=" + statusUrl + ", topicNames=" + topicNames
				+ "]";
	}
	
	
}
